package phase01.module3.code.question5;

import java.util.Objects;

/**
 * 扑克类，包含牌号，花色，和牌的大小
 */
public class Card implements Comparable<Card> {
    private final int serial; // 1 - 15

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    private int rank;
    private final CardSuit cardSuit;

    public Card(int cardSerial, CardSuit cardSuit, int rank) {
        serial = cardSerial;
        this.rank = rank;
        this.cardSuit = cardSuit;
    }

    @Override
    public String toString() {
        String serialString;
        if (serial == 1) {
            serialString = "A";
        } else if (serial > 1 && serial <= 10) {
            serialString = Integer.toString(serial);
        }else if (serial == 11) {
            serialString = "J";
        } else if (serial == 12) {
            serialString = "Q";
        } else if (serial == 13) {
            serialString = "K";
        } else if (serial == 14) {
            serialString = "小王";
        } else {
            serialString = "大王";
        }
        return cardSuit + " " + serialString;
    }

    public int compareTo(Card card) {
        return this.getRank() - card.getRank();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Card card = (Card) o;
        return serial == card.serial && cardSuit == card.cardSuit;
    }

    @Override
    public int hashCode() {
        return Objects.hash(serial, cardSuit);
    }

    public int getSerial() {
        return serial;
    }

    public CardSuit getCardSuit() {
        return cardSuit;
    }
}
